package cn.rkylin.oms.common.event.message;

import com.google.common.collect.Lists;

import java.util.List;

import static cn.rkylin.oms.common.event.message.ReceiverType.*;

public class MessageReceiverBuilder {

    private List<MessageReceiver> receivers = Lists.newArrayList();

    public static MessageReceiverBuilder builder() {
        return new MessageReceiverBuilder();
    }

    public MessageReceiverBuilder user(String id) {
        return receiver(USER, id);
    }

    public MessageReceiverBuilder role(String id) {
        return receiver(ROLE, id);
    }

    public MessageReceiverBuilder unit(String id) {
        return receiver(UNIT, id);
    }

    private MessageReceiverBuilder receiver(ReceiverType type, String id) {
        MessageReceiver receiver = new MessageReceiver();
        receiver.setReceiverType(USER);
        receiver.setReceiverId(id);
        receivers.add(receiver);
        return this;
    }

    public List<MessageReceiver> build() {
        return Lists.newArrayList(receivers);
    }

}
